//
//  DSSHMeTaskVC.m
//  DSSH
//
//  Created by lcy on 16/3/29.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHMeTaskVC.h"
#import "UIView+Round.h"
#import "DSSHTaskTableVC.h"
@interface DSSHMeTaskVC ()<UITableViewDataSource,UITableViewDelegate>
{
    UIButton * _selectedTitleBtn;

}
@property(nonatomic,strong)UITableView* myTaskTableView;
@end

@implementation DSSHMeTaskVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"我的任务";
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    self.view.backgroundColor = [UIColor whiteColor];
    self.myTaskTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ZYAppWidth, ZYAppHeight) style:UITableViewStyleGrouped];
    self.myTaskTableView.delegate = self;
    self.myTaskTableView.dataSource = self;
    self.myTaskTableView.scrollEnabled = NO;
    [self.view addSubview:self.myTaskTableView];
    
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 2;
    }else
    {
        return 1;
    }
    
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    if (indexPath.section == 0)
    {
        UIButton * finishedTaskBtn = [UIButton new];
        [finishedTaskBtn setTitle:@"我做的任务" forState:UIControlStateNormal];
        [finishedTaskBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        finishedTaskBtn.titleLabel.font = FONT(13);
        [finishedTaskBtn getRoundView:5];
        finishedTaskBtn.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell.contentView addSubview:finishedTaskBtn];
        
        [finishedTaskBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(cell.contentView.mas_left).with.offset(25*WIDTH_SCALE);
            make.centerY.mas_equalTo(cell.contentView.mas_centerY);
            make.height.mas_equalTo(30*HIGHT_SCALE);
            make.width.mas_equalTo((ZYAppWidth-25*4)/3);
        }];

    }else
    {
        if (indexPath.row == 0)
        {
            NSArray * titleArray = [[NSArray alloc]initWithObjects:@"待确认",@"待收画",@"执行中",@"已完成", nil];
            for (int i = 0; i<4; i++)
            {
                UIButton * button = [UIButton new];
                
                button.frame = CGRectMake(15+(40+(ZYAppWidth-15*2*WIDTH_SCALE-40*3*WIDTH_SCALE)/4)*WIDTH_SCALE*i, 7*HIGHT_SCALE, (ZYAppWidth-15*2*WIDTH_SCALE-40*3*WIDTH_SCALE)/4, 30*HIGHT_SCALE);
                button.tag = i;
                [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                button.titleLabel.font = FONT(13);
                [button setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
                if (i == 0)
                {
                    _selectedTitleBtn = button;
                    _selectedTitleBtn.selected = YES;
                }
                [button setTitle:titleArray[i] forState:UIControlStateNormal];
                [button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
                [cell.contentView addSubview:button];
                
            }

        }else
        {
            DSSHTaskTableVC * tableVC = [[DSSHTaskTableVC alloc]init];
            tableVC.view.frame = cell.contentView.frame;
            [cell.contentView addSubview:tableVC.view];
            cell.contentView.backgroundColor = [UIColor orangeColor];
            [self addChildViewController:tableVC];
        }
        
    }
    return cell;
}
-(void)clickBtn:(UIButton*)btn
{
    _selectedTitleBtn.selected = NO;
    _selectedTitleBtn = btn;
    btn.selected = YES;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5*HIGHT_SCALE;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        if (indexPath.row == 1)
        {
            return ZYAppHeight-44*2*HIGHT_SCALE-5*HIGHT_SCALE-64;
        }
    }
   return 44*HIGHT_SCALE;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
